﻿using System;
using System.Collections.Generic;
using UniRx;
using UniRx.Triggers;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

namespace Studio
{
	// Token: 0x020005BC RID: 1468
	public class BGMControl : MonoBehaviour
	{
		// Token: 0x06002563 RID: 9571 RVA: 0x000DD7F0 File Offset: 0x000DB9F0
		private void OnClickRepeat()
		{
			Singleton<Studio>.Instance.bgmCtrl.repeat = ((Singleton<Studio>.Instance.bgmCtrl.repeat != BGMCtrl.Repeat.None) ? BGMCtrl.Repeat.None : BGMCtrl.Repeat.All);
			this.buttonRepeat.image.sprite = this.spriteRepeat[(Singleton<Studio>.Instance.bgmCtrl.repeat != BGMCtrl.Repeat.None) ? 1 : 0];
		}

		// Token: 0x06002564 RID: 9572 RVA: 0x000DD85C File Offset: 0x000DBA5C
		private void OnClickStop()
		{
			Singleton<Studio>.Instance.bgmCtrl.Stop();
		}

		// Token: 0x06002565 RID: 9573 RVA: 0x000DD870 File Offset: 0x000DBA70
		private void OnClickPlay()
		{
			Singleton<Studio>.Instance.bgmCtrl.Play();
		}

		// Token: 0x06002566 RID: 9574 RVA: 0x000DD884 File Offset: 0x000DBA84
		private void OnClickPause()
		{
			Singleton<Studio>.Instance.bgmCtrl.Pause();
		}

		// Token: 0x06002567 RID: 9575 RVA: 0x000DD898 File Offset: 0x000DBA98
		private void OnClickExpansion()
		{
			this.objBottom.SetActive(!this.objBottom.activeSelf);
			this.buttonExpansion.image.sprite = this.spriteExpansion[(!this.objBottom.activeSelf) ? 0 : 1];
		}

		// Token: 0x06002568 RID: 9576 RVA: 0x000DD8EC File Offset: 0x000DBAEC
		private void OnClickSelect(int _idx)
		{
			StudioNode studioNode = null;
			if (this.dicNode.TryGetValue(Singleton<Studio>.Instance.bgmCtrl.no, out studioNode))
			{
				studioNode.select = false;
			}
			Singleton<Studio>.Instance.bgmCtrl.no = _idx;
			if (this.dicNode.TryGetValue(Singleton<Studio>.Instance.bgmCtrl.no, out studioNode))
			{
				studioNode.select = true;
			}
		}

		// Token: 0x06002569 RID: 9577 RVA: 0x000DD95C File Offset: 0x000DBB5C
		private void InitList()
		{
			for (int i = 0; i < this.transformRoot.childCount; i++)
			{
				UnityEngine.Object.Destroy(this.transformRoot.GetChild(i).gameObject);
			}
			this.transformRoot.DetachChildren();
			foreach (KeyValuePair<int, Info.LoadCommonInfo> keyValuePair in Singleton<Info>.Instance.dicBGMLoadInfo)
			{
				GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(this.objectNode);
				gameObject.transform.SetParent(this.transformRoot, false);
				StudioNode component = gameObject.GetComponent<StudioNode>();
				component.active = true;
				int idx = keyValuePair.Key;
				component.addOnClick = delegate()
				{
					this.OnClickSelect(idx);
				};
				component.text = keyValuePair.Value.name;
				this.dicNode.Add(idx, component);
			}
			StudioNode studioNode = null;
			if (this.dicNode.TryGetValue(Singleton<Studio>.Instance.bgmCtrl.no, out studioNode))
			{
				studioNode.select = true;
			}
		}

		// Token: 0x0600256A RID: 9578 RVA: 0x000DDAA4 File Offset: 0x000DBCA4
		private void Awake()
		{
			this.buttonRepeat.onClick.AddListener(new UnityAction(this.OnClickRepeat));
			this.buttonStop.onClick.AddListener(new UnityAction(this.OnClickStop));
			this.buttonPlay.onClick.AddListener(new UnityAction(this.OnClickPlay));
			this.buttonPause.onClick.AddListener(new UnityAction(this.OnClickPause));
			this.buttonExpansion.onClick.AddListener(new UnityAction(this.OnClickExpansion));
			this.InitList();
			this.UpdateAsObservable().Subscribe(delegate(Unit _)
			{
				this.imagePlayNow.enabled = Singleton<Studio>.Instance.bgmCtrl.play;
			});
		}

		// Token: 0x0600256B RID: 9579 RVA: 0x000DDB5C File Offset: 0x000DBD5C
		private void OnEnable()
		{
			this.buttonRepeat.image.sprite = this.spriteRepeat[(Singleton<Studio>.Instance.bgmCtrl.repeat != BGMCtrl.Repeat.None) ? 1 : 0];
			foreach (KeyValuePair<int, StudioNode> keyValuePair in this.dicNode)
			{
				keyValuePair.Value.select = false;
			}
			StudioNode studioNode = null;
			if (this.dicNode.TryGetValue(Singleton<Studio>.Instance.bgmCtrl.no, out studioNode))
			{
				studioNode.select = true;
			}
		}

		// Token: 0x040025D2 RID: 9682
		[SerializeField]
		private GameObject objectNode;

		// Token: 0x040025D3 RID: 9683
		[SerializeField]
		private Transform transformRoot;

		// Token: 0x040025D4 RID: 9684
		[SerializeField]
		private Button buttonRepeat;

		// Token: 0x040025D5 RID: 9685
		[SerializeField]
		private Sprite[] spriteRepeat;

		// Token: 0x040025D6 RID: 9686
		[SerializeField]
		private Button buttonStop;

		// Token: 0x040025D7 RID: 9687
		[SerializeField]
		private Button buttonPlay;

		// Token: 0x040025D8 RID: 9688
		[SerializeField]
		private Image imagePlayNow;

		// Token: 0x040025D9 RID: 9689
		[SerializeField]
		private Button buttonPause;

		// Token: 0x040025DA RID: 9690
		[SerializeField]
		private Button buttonExpansion;

		// Token: 0x040025DB RID: 9691
		[SerializeField]
		private Sprite[] spriteExpansion;

		// Token: 0x040025DC RID: 9692
		[SerializeField]
		private GameObject objBottom;

		// Token: 0x040025DD RID: 9693
		private Dictionary<int, StudioNode> dicNode = new Dictionary<int, StudioNode>();
	}
}
